package com.team.engine.common.view;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

/**
 * struts2的基础action <br/>
 * 可以让继承的action类，获得原始的session，request和response
 * @author MengLH
 * @data 2010-5-31
 */

public abstract class BaseActionAbs extends ActionSupport implements ServletRequestAware, ServletResponseAware, SessionAware, ServletContextAware{

	private static final long serialVersionUID = -3330790292509646784L;
	
	protected Map<String, Object> session;
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected ServletContext servletContext;
	protected String token;
	
	/**
	 * 检查是否重复提交<br/>
	 * 重复提交是true，不重复是false;
	 * @return
	 */
	public boolean isCheckToken(){
		String tokenSession = (String) session.get("token");
		if(tokenSession != null && tokenSession.equals(this.token)){
			this.request.setAttribute("error", "请不要重复提交");
			return true;
		}
		return false;
	}

	public void setToken(String token) {
		this.token = token;
	}
	
	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	
}
